package com.emuporium.gymrat.server.routine;

import java.io.IOException;
import java.util.LinkedHashMap;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.emuporium.gymrat.server.data.ExerciseDB;
import com.emuporium.gymrat.server.data.Routine;
import com.emuporium.gymrat.server.data.RoutineDB;

@SuppressWarnings("serial")
public class RoutineModifyServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		int routineId = new Integer(request.getParameter("id")).intValue();
		Routine routine = RoutineDB.selectRoutine(routineId);
		LinkedHashMap<Integer,String> groups = ExerciseDB.selectMuscleGroups();
		
		request.setAttribute("routine", routine);
		request.setAttribute("result", "");
		request.setAttribute("groups", groups);

		String url = "/routine/modify.jsp";
		RequestDispatcher dispatcher = getServletContext()
				.getRequestDispatcher(url);
		dispatcher.forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}
